from pathlib import Pathimport pandas as pdimport geopandas as gpdimport requestsimport censusdataBASE_DIR = Path(".").resolve()DATA_DIR = BASE_DIR /"Data"RAW_DIR = DATA_DIR /"raw"PROCESSED_DIR = DATA_DIR /"processed"PROCESSED_DIR.mkdir(parents=True, exist_ok=True)
1.1 Data Collection
We first set up a clear project directory structure using pathlib, defining base, raw, and processed data folders. We then load Philadelphia census block group polygons from the GeoJSON file obtained from OpenDataPhilly. Census block groups serve as our spatial unit of analysis because they provide an appropriate balance between demographic detail, geographic precision, and data availability for evaluating bicycle infrastructure equity in Philadelphia. We also inspect the number of block groups and the coordinate reference system (CRS) to confirm that the spatial units are suitable for further analysis.
To access socioeconomic variables at the block group level within Philadelphia County, we use the censusdata package to download 2023 ACS 5-year estimates. The selected variables include total population, median household income, zero-vehicle households, and bicycle commuters.
Because the ACS download uses a hierarchical geography index, we reconstruct a full 12-digit GEOID by defining a helper function make_geoid_full that concatenates state, county, tract, and block group codes from x.geo. This reconstructed GEOID is then used to merge the ACS dataset with the block group geometries using a left join. ACS error codes and placeholder values are replaced with NaN to ensure the dataset is clean and reliable for further analysis.
For Indego station locations, we access the real-time API endpoint to retrieve live station data. The returned GeoJSON is parsed into a GeoDataFrame with CRS EPSG:4326. This ensures that the station dataset is up to date and ready for spatial processing.
To perform accurate distance calculations, both census block groups and Indego stations are reprojected into a common projected CRS: EPSG:2272. This projection allows distance to be measured in feet and ensures consistency across all geospatial operations.
1.5 Interactive Block Group Map with Socioeconomic Data
We created an interactive map using Folium to visualize demographic characteristics at the census block group level. The map includes a hover tooltip that displays each block group’s total population, median household income, number of zero-vehicle households, and number of bicycle commuters. This allows users to explore socioeconomic patterns across the city and provides important context for interpreting later need and access metrics.
Make this Notebook Trusted to load map: File -> Trust Notebook
1.6 Exploratory Map of Active Indego Bike Stations
We also mapped the current active Indego bike stations to visualize their spatial distribution across Philadelphia. This map helps illustrate where stations are located within block groups and highlights their concentration in the central parts of the city. As shown, most active stations are clustered in central Philadelphia, with limited extensions into South Philadelphia. This pattern reflects historical funding constraints and previous boundaries of the service area.